//
//  OPMrestCookHeadView.m
//  OnePiece
//
//  Created by wsy on 15/10/29.
//  Copyright © 2015年 wsy. All rights reserved.
//

#import "OPMrestCookHeadView.h"
#import <UIImageView+WebCache.h>
@implementation OPMrestCookHeadView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _piture = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH*235/600)];
        [self addSubview:_piture];
        _address = [[UILabel alloc]initWithFrame:CGRectMake(10, SCREEN_WIDTH*235/600+5, SCREEN_WIDTH-80, 15)];
        _address.font = [UIFont systemFontOfSize:12];
        [self addSubview:_address];
        _address_origin = [[UILabel alloc]initWithFrame:CGRectMake(10, SCREEN_WIDTH*235/600+25, SCREEN_WIDTH-80, 30)];
        _address_origin.font = [UIFont systemFontOfSize:12];
        _address_origin.numberOfLines = 0;
        [self addSubview:_address_origin];
        _cashimg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"iconfont-6"]];
        _cashimg.frame = CGRectMake(10, SCREEN_WIDTH*235/600+60, 20, 20);
        [self addSubview:_cashimg];
        _timeimg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"iconfont-naozhong"]];
        _timeimg.frame = CGRectMake(10, SCREEN_WIDTH*235/600+90, 20, 20);
        [self addSubview:_timeimg];
        _phoneimg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"iconfont-phone"]];
        _phoneimg.frame = CGRectMake(10, SCREEN_WIDTH*235/600+120, 20, 20);
        [self addSubview:_phoneimg];
        _cost = [[UILabel alloc]initWithFrame:CGRectMake(35, SCREEN_WIDTH*235/600+60, 150, 20)];
        _cost.font = [UIFont systemFontOfSize:12];
        [self addSubview:_cost];
        _time = [[UILabel alloc]initWithFrame:CGRectMake(35, SCREEN_WIDTH*235/600+90, 260, 20)];
        _time.font = [UIFont systemFontOfSize:12];
        [self addSubview:_time];
        _phone = [[UILabel alloc]initWithFrame:CGRectMake(35, SCREEN_WIDTH*235/600+120, 150, 20)];
        _phone.font = [UIFont systemFontOfSize:12];
        [self addSubview:_phone];
        _reasonLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, SCREEN_WIDTH*235/600+150, 100, 20)];
        _reasonLabel.text = @"推荐理由";
        _reasonLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:_reasonLabel];
        _reasonDesc = [[UILabel alloc]initWithFrame:CGRectMake(15, SCREEN_WIDTH*235/600+175, SCREEN_WIDTH-30, 20)];
        _reasonDesc.numberOfLines = 0;
        _reasonDesc.textColor = [UIColor colorWithWhite:0.286 alpha:1.000];
        _reasonDesc.font = [UIFont systemFontOfSize:12];
        [self addSubview:_reasonDesc];
    }
    return self;
}

- (void)setModel:(OPMrestInfoModel *)model
{
    [_piture sd_setImageWithURL:[NSURL URLWithString:model.imgs[0]] placeholderImage:[UIImage imageNamed:@"beijingImg.jpg"]];
    _address.text = model.address;
    _address_origin.text = model.address_origin;
    _cost.text = [NSString stringWithFormat:@"人均：%@元",model.cost];
    _time.text = [NSString stringWithFormat:@"营业时间：%@",model.open_time];
    _phone.text = [NSString stringWithFormat:@"电话：%@",model.phone];
    _reasonDesc.text = model.desc;
    _reasonDesc.frame = CGRectMake(15, SCREEN_WIDTH*235/600+175, SCREEN_WIDTH-30, [OPMrestCookHeadView heightOfString:model.desc]);
}

+ (CGFloat)heightOfString:(NSString *)str
{
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:12] forKey:NSFontAttributeName];
    CGRect bounds = [str boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 30, 0) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dic context:nil];
    return bounds.size.height;
}

+ (CGFloat)heightForHead:(OPMrestInfoModel *)model
{
    return SCREEN_WIDTH*235/600+180+[OPMrestCookHeadView heightOfString:model.desc];
}

@end
